
import mx.collections.ArrayCollection;
import mx.collections.Sort;
import mx.collections.SortField;

import net.optix.ip.model.ModelLocator;
import net.optix.ip.vo.InventionVO;
[Bindable]
private var model:ModelLocator	=	ModelLocator.getInstance();

private var _inventions:ArrayCollection;
public function set inventions(value:ArrayCollection):void
{
	_inventions	=	value;
	trace(value.length+"  valeu length");
	trace(this.selectedIndex+"   selectedindex");
	var i	=	this.selectedIndex;
	switch(i)
	{
		case -1:
			showAllInventions();
			break;
		case 0:
			showAllInventions();
			break;
		case 1:
			showPatentApplications();
			break;
		case 2:
			showApplicationsInExams();
			break;
		case 3:
			showIssuedPatents();
			break;
		case 4:
			showAbandonments();
			break;
	}
}

public function showClientInventions():void
{
	var i	=	this.selectedIndex;
	switch(i)
	{
		case 0:
			showAllInventions();
			break;
		case 1:
			showPatentApplications();
			break;
		case 2:
			showApplicationsInExams();
			break;
		case 3:
			showIssuedPatents();
			break;
		case 4:
			showAbandonments();
			break;
	}
}

public function get inventions():ArrayCollection
{
	return _inventions;
}

private function showInventions():void
{
	var clientInventions:ArrayCollection	=	new ArrayCollection();
	var invention:InventionVO;
	for(var i:int=0; i<_inventions.length; i++)
	{
		invention	=	_inventions[i];
		if(invention.type == -1)
		{
			clientInventions.addItem(invention);
		}
	}
	var sortField:SortField	=	new SortField();
	sortField.name			=	"value";
	sortField.descending	=	true;
	
	var sortField2:SortField	=	new SortField();
	sortField2.name			=	"lastActionDate";
	sortField2.descending	=	true;
	
	var sort:Sort			=	new Sort();
	sort.fields				=	[sortField2,sortField];
	
	clientInventions.sort	=	sort;
	clientInventions.refresh();
	model.firmInventions	=	clientInventions;
}

private function showPatentApplications():void
{
	var clientInventions:ArrayCollection	=	new ArrayCollection();
	var invention:InventionVO;
	for(var i:int=0; i<_inventions.length; i++)
	{
		invention	=	_inventions[i];
		if(invention.type>=-1 && invention.type<=1 && invention.status < 6)
		{
			clientInventions.addItem(invention);
		}
	}
	
	var sortField:SortField	=	new SortField();
	sortField.name			=	"actionDueDate";
	sortField.descending	=	true;
	
	var sort:Sort			=	new Sort();
	sort.fields				=	[sortField];
	
	clientInventions.sort	=	sort;
	clientInventions.refresh();
	
	model.firmInventions	=	clientInventions;
}

private function showApplicationsInExams():void
{
	var clientInventions:ArrayCollection	=	new ArrayCollection();
	var invention:InventionVO;
	for(var i:int=0; i<_inventions.length; i++)
	{
		invention	=	_inventions[i];
		if(invention.status >= 6 && invention.status !=9 && invention.ufDate != "" && invention.ufDate!="0000-00-00")
		{
			clientInventions.addItem(invention);
		}
	}
	
	var sortField:SortField	=	new SortField();
	sortField.name			=	"actionDueDate";
	sortField.descending	=	true;
	
	var sort:Sort			=	new Sort();
	sort.fields				=	[sortField];
	
	clientInventions.sort	=	sort;
	clientInventions.refresh();
	model.firmInventions	=	clientInventions;
}

private function showIssuedPatents():void
{
	var clientInventions:ArrayCollection	=	new ArrayCollection();
	var invention:InventionVO;
	for(var i:int=0; i<_inventions.length; i++)
	{
		invention	=	_inventions[i];
		if(invention.status == 9)
		{
			clientInventions.addItem(invention);
		}
	}
	
	var sortField:SortField	=	new SortField();
	sortField.name			=	"actionDueDate";
	sortField.descending	=	true;
	
	var sort:Sort			=	new Sort();
	sort.fields				=	[sortField];
	
	clientInventions.sort	=	sort;
	clientInventions.refresh();
	
	model.firmInventions	=	clientInventions;
}

private function showAllInventions():void
{
	var sortField:SortField	=	new SortField();
	sortField.name			=	"actionDueDate";
	sortField.descending	=	true;
	
	var sort:Sort			=	new Sort();
	sort.fields				=	[sortField];
	
	_inventions.sort	=	sort;
	_inventions.refresh();
	
	model.firmInventions	=	_inventions;
	
}

private function showAbandonments():void
{
	var clientInventions:ArrayCollection	=	new ArrayCollection();
	var invention:InventionVO;
	for(var i:int=0; i<_inventions.length; i++)
	{
		invention	=	_inventions[i];
		if(invention.status == 10)
		{
			clientInventions.addItem(invention);
		}
	}
	
	var sortField:SortField	=	new SortField();
	sortField.name			=	"actionDueDate";
	sortField.descending	=	true;
	
	var sort:Sort			=	new Sort();
	sort.fields				=	[sortField];
	
	clientInventions.sort	=	sort;
	clientInventions.refresh();
	model.firmInventions	=	clientInventions;
}